package com.example.hello.client.PasswordTextBox;

import com.example.hello.BootstrapPasswordTextBox;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.ValueBoxBase;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.communication.StateChangeEvent;
import com.vaadin.client.ui.AbstractComponentConnector;
import com.vaadin.shared.ui.Connect;

@Connect(BootstrapPasswordTextBox.class)
public class BootstrapPasswordTextBoxConnector extends AbstractComponentConnector {

    @Override
    protected Widget createWidget() {
        return GWT.create(VBootstrapPasswordTextBox.class);
    }

    @Override
    public VBootstrapPasswordTextBox getWidget() {
        return (VBootstrapPasswordTextBox) super.getWidget();
    }

    @Override
    public BootstrapPasswordTextBoxState getState() {
        return (BootstrapPasswordTextBoxState) super.getState();
    }

    @Override
    public void onStateChanged(StateChangeEvent stateChangeEvent) {
        super.onStateChanged(stateChangeEvent);

        BootstrapPasswordTextBoxState state = getState();

        VBootstrapPasswordTextBox passwordTextBox = getWidget();

        passwordTextBox.setText(state.getText());
        passwordTextBox.setAlignment(ValueBoxBase.TextAlignment.valueOf(state.getAlignment()));
        passwordTextBox.setMaxLength(state.getMaxLength());
        passwordTextBox.setVisibleLength(state.getVisibleLength());
    }

}
